home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / cmat.doc < prev    next >
Text File  |  1995-03-31  |  4KB  |  114 lines

  1.   Resp: 2 of 2 by wes at kuhub.cc.ukans.edu 
  2. Author: [Wes Hubert] 
  3.   Date: Thu Apr 04 1991 22:56  
  4.  Lines: 238 
  5.  
  6.  
  7.   
  8. CMAT is an HP48 program for performing operations on columns of a 
  9. matrix. CMAT iterates over each row of the matrix, treating the n 
  10. columns of the matrix as if they were variables named C1, C2, ... 
  11. Cn, or, optionally, as if they were named with user-specified 
  12. names. The operations can be be limited to selected rows of the 
  13. matrix by supplying a boolean condition that must be met before 
  14. the computation is peformed. If the result column is not in the 
  15. original matrix, the matrix will be expanded to include the new 
  16. column. 
  17.   
  18. Before executing CMAT, you must place on level two of the stack 
  19. the matrix object to process, and on level one of the stack either 
  20. an algebraic object that specifies the compuation to perform or a 
  21. list that specifies a series of variable names, conditions, and 
  22. computations. 
  23.   
  24. For example, place the matrix 
  25.   
  26. [[ 1 5 ] 
  27.  [ 2 4 ] 
  28.  [ 3 6 ]] 
  29.   
  30. on the stack. 
  31.   
  32. Next place the algebraic object 
  33.   
  34. 'C4=C2^2+C1' 
  35.   
  36. on the stack. It specifies computing a new column, column four, as 
  37. column two squared plus column one. Since column three is not part 
  38. of the original matrix, it is filled with zeros. 
  39.   
  40. Executing CMAT will replace these objects with the matrix: 
  41.   
  42. [[ 1 5 0 26 ] 
  43.  [ 2 4 0 18 ] 
  44.  [ 3 6 0 39 ]] 
  45.   
  46.   
  47. The Evaluation List 
  48.   
  49. For computations to complex to specify with a single equation, CMAT 
  50. allows an evaluation list instead of an equation.  The list can contain 
  51. name assignment lists and conditional expression lists as well as 
  52. equations.  Each list begins with a string.  "Names", "If', or "Compute". 
  53. The first character is sufficient (e.g. "N" for "Names).  A name list 
  54. consists of one or more lists whose first item is a column number and 
  55. whose second item is a name for the column.  A conditional list contains 
  56. and algebraic object specifying a condition that must be true for a row 
  57. in order for the following equation to be processed.  An imperative 
  58. list contains an equation, and is equivalent to an equation by itself 
  59. not contained in a list (e.g. {"C" 'equation'} and 'equation' are 
  60. treated identically. 
  61.   
  62.   Name List    {"Names" {2 'Age'} {3 'Income'}} 
  63.   Conditional  {"If" 'boolean' 'equation'} 
  64.   Imperative   {"Compute" 'equation'} 
  65.   
  66. If a column is not explicitly named, it has a default of of Cn where 
  67. 'n' is the column number, but 'Cn' cannot be used to specify a column 
  68. that has been named.  It must be called by its name. 
  69.   
  70. An example list: 
  71.   { { "N" {4 'Sum'} {5 Mean'}} 
  72.     'Sum=C1+C2+C3' 
  73.     { "If" 'C1>0' 'Mean=Sum/3' } } 
  74.   
  75.   
  76. Immediate Execution Functions 
  77.   
  78. Functions that are available only for immediate execution from the 
  79. keyboard can be placed into programs by saving them in a program. 
  80. For example, RAND cannot be used directly in an algebraic 
  81. expression, but 
  82.   
  83. << RAND >> 'RANDOM' STO 
  84.   
  85. creates a random number function that can then be used in an 
  86. algebraic expression such as 
  87.   
  88. 'C1=TRNC(10*RANDOM,0)' 
  89.   
  90. to create a column of random numbers in the range 0 through 9. 
  91.   
  92.   
  93. Missing Value Indicators 
  94.   
  95. To handle missing data, filter column variables with functions 
  96. such VALID and VALUE in the example below. In this example, 
  97. negative values indicate invalid data. The function VALID returns 
  98. 1 if its argument is in the valid data range, 0 otherwise. The 
  99. function VALUE returns the original data value if it is in the 
  100. valid data range, 0 otherwise. Using these functions, C4 counts 
  101. the number of valid data points, C5 the total of valid data 
  102. values, and C6 the mean of the valid data. 
  103.   
  104. << << n | IF 'n>-1' THEN 1 ELSE 0 END >> >> 'VALID' STO 
  105.   
  106. << << n | IF 'n>-1' THEN n ELSE 0 END >> >> 'VALUE' STO 
  107.   
  108. { 'C4=VALID(C1)+VALID(C2)+VALID(C3)' 
  109.   'C5=VALUE(C1)+VALUE(C2)+VALUE(C3)' 
  110.   {"IF" 'C4>0' 'C6=C5/C4'} } 
  111.   
  112. The condition 'C4>0'prevents dividing by zero when evaluating the 
  113. expression for C6 if there are no valid values in a row. 
  114.